<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    
        $counter = 200;
        $int_option = array("options"=>array("min_range"=>0, "max_range"=>100));
        
        $firstName = $_POST["firstName"];
        $lastName = $_POST["lastName"];
        $month = $_POST["month"];
        $year = $_POST["year"];
        $major = $_POST["major"];
        
        /*
        if(strlen($year) == 0){
            echo "year is empty";
        }else{
            if(!filter_var($year, FILTER_VALIDATE_INT, $int_option)){
                echo "year is not integer in range";
            }
        }
         * */
        
        $con = mysql_connect("localhost", "zhouzhao", "19831022");
        if(!$con){
            die("could NOT connect to DB".mysql_error());
        }else{
            echo "DB is connected";
        }
        
        mysql_select_db("test", $con);
        
        $result = mysql_query("select * from students");
        
        while($row = mysql_fetch_assoc($result)){
            echo $row["firstName"]." ".$row["lastName"];
            echo "<br/>";
        }
        
        if(!mysql_query("insert into students values ('$counter', '$firstName', '$lastName', '$year-$month-22', '$major')")){
            die("error: ".mysql_errno());
        }else{
            echo "1 recored is added";
        }
        
        mysql_close($con);
        $counter++;
?>
